<template>
  <div class="page-container">
    <el-dialog
      width="950px"
      v-model="dialogForm.dialogFormVisible"
      :title="dialogForm.content"
    >
      <el-form
        ref="ruleFormRef"
        style="width: 900px"
        :model="ruleForm"
        :rules="rules"
        label-width="auto"
        class="demo-ruleForm"
      >
        <el-form-item label="学生学号" prop="stuNo" style="width: 200px">
          <el-input v-model="ruleForm.stuNo" />
        </el-form-item>
        <el-form-item label="学生姓名" prop="stuName" style="width: 200px">
          <el-input v-model="ruleForm.stuName" />
        </el-form-item>
        <el-form-item label="学生班级" prop="className" style="width: 200px">
          <el-input v-model="ruleForm.className" />
        </el-form-item>
        <el-form-item label="毕业薪资" prop="salary" style="width: 200px">
          <el-input v-model="ruleForm.salary" type="number" />
        </el-form-item>
        <el-form-item label="上班城市" prop="workCity" style="width: 200px">
          <el-select v-model="ruleForm.workCity" placeholder="选择城市">
            <el-option label="上海" value="上海" />
          </el-select>
        </el-form-item>
        <el-form-item label="专&emsp;&emsp;业" prop="expertiseId">
          <el-select v-model="ruleForm.expertiseId" placeholder="请选择专业">
            <el-option
              :label="v.value"
              :value="v.key"
              v-for="(v, i) in options"
              :key="i"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          label="市&nbsp;场&nbsp;部"
          prop="origin"
          style="width: 200px"
        >
          <el-input v-model="ruleForm.origin" />
        </el-form-item>
        <el-form-item label="学&emsp;&emsp;院" prop="collegeId">
          <el-select v-model="ruleForm.collegeId" placeholder="请选择">
            <el-option label="游戏学院" :value="1" />
            <el-option label="网站工程学院" :value="2" />
          </el-select>
        </el-form-item>
        <el-form-item label="毕业年份" prop="gradYear">
          <el-date-picker
            v-model="ruleForm.gradYear"
            type="year"
            placeholder="选择毕业年份"
          />
        </el-form-item>
        <el-form-item label="学生状态" prop="status">
          <el-radio-group v-model="ruleForm.status">
            <el-radio label="1">未毕业</el-radio>
            <el-radio label="2">返校重听</el-radio>
            <el-radio label="3">已就业</el-radio>
            <el-radio label="4">返回未就业</el-radio>
            <el-radio label="5">以往未就业</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="dialogForm.dialogFormVisible = false"
            >取消</el-button
          >
          <el-button type="primary" @click="submitForm(ruleFormRef)">
            确定
          </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
<script setup>
/**
 * 模块引入
 */

import { reactive, ref, toRefs } from "vue";
import { useRouter, useRoute } from "vue-router";
const router = useRouter();
const route = useRoute();
const formLabelWidth = "140px";
// const props = defineProps(["dialogFormVisible"]);
// let { dialogFormVisible } = toRefs(props);
const props = defineProps({
  dialogForm: {
    type: Object,
    default: {
      dialogFormVisible: false,
      content: "新增",
    },
  },
  ruleForm: {
    type: Object,
  },
});
const studentForm = ref({});
const emit = defineEmits(["centerDialogVisible"]);
const options = ref([
  {
    value: "游戏设计",
    key: 2,
  },
  {
    value: "游戏开发",
    key: 1,
  },
  {
    value: "元宇宙",
    key: 3,
  },
]);
const ruleFormRef = ref();
const rules = reactive({
  stuNo: [
    {
      required: true,
      message: "学号不能为空",
      trigger: "blur",
    },
    { min: 11, max: 11, message: "学号必须为11位", trigger: "change" },
  ],
  stuName: [
    {
      required: true,
      message: "学生姓名必填",
      trigger: "blur",
    },
  ],
  className: [
    {
      required: true,
      message: "学生班级必填",
      trigger: "blur",
    },
  ],
  salary: [
    {
      required: true,
      message: "毕业薪资必填",
      trigger: "blur",
    },
  ],
  workCity: [
    {
      required: true,
      message: "上班城市必选",
      trigger: "change",
    },
  ],
  expertiseName: [
    {
      required: true,
      message: "专业必选",
      trigger: "change",
    },
  ],
  origin: [
    {
      required: true,
      message: "市场部必填",
      trigger: "blur",
    },
  ],
  collegeName: [
    {
      required: true,
      message: "学院必选",
      trigger: "change",
    },
  ],
  gradYear: [
    {
      required: true,
      message: "毕业年份必选",
      trigger: "change",
    },
  ],
  status: [
    {
      required: true,
      message: "学生状态必选",
      trigger: "change",
    },
  ],
});
/**
 * 数据
 */
const state = reactive({});

const submitForm = async (ruleFormRef) => {
  if (!ruleFormRef) return;
  await ruleFormRef.validate((valid, fields) => {
    if (valid) {
      studentForm.value = props.ruleForm;
      emit("centerDialogVisible", studentForm);
      props.dialogForm.dialogFormVisible = false;
    } else {
      console.log("error submit!", fields);
    }
  });
};
/**
 * 功能方法
 */
</script>
<style lang="scss" scoped>
.el-dialog__body {
  display: flex;
  .el-form {
    display: flex;
    flex-wrap: wrap;
  }
}
</style>
